package com.gexiaobao.pigeon.ui.adapter

import android.graphics.Paint
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.RaceInfoResponse
import com.gexiaobao.pigeon.databinding.ItemOrgPassBinding
import com.gexiaobao.pigeon.ui.view.PieProgressBar

/**
 * @Author      : hxw
 * @Date        : 2024/5/28 8:20
 * @Describe    :
 */
class OrgPassAdapter(data: ArrayList<RaceInfoResponse.PassListBean>) :
    BaseQuickAdapter<RaceInfoResponse.PassListBean, DataBindBaseViewHolder>(R.layout.item_org_pass, data) {
    override fun convert(holder: DataBindBaseViewHolder, item: RaceInfoResponse.PassListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemOrgPassBinding
        binding.data = item
        binding.executePendingBindings()

        val tvItemOrgPassGatherCount = holder.getView<AppCompatTextView>(R.id.tvItemOrgPassGatherCount)
        tvItemOrgPassGatherCount.paint.flags = Paint.UNDERLINE_TEXT_FLAG//设置下划线

        val bar = holder.getView<PieProgressBar>(R.id.pieProgressBar)
        bar.setProgress(item.backPercent)
        holder.setText(
            R.id.tvItemHomingRate,
            context.getString(R.string.Homing_rate) + " " + if (item.backPercent == 0) "--" else item.backPercent.toString() + "%"
        )

        val ivLiving = holder.getView<AppCompatImageView>(R.id.ivLiving)
        Glide.with(context).asGif().load(R.mipmap.icon_living).into(ivLiving)
        val gatherLiveStatus = item.gatherLiveStatus
        val carLiveStatus = item.carLiveStatus
        val backLiveStatus = item.backLiveStatus
        val passStatus = item.passStatus

        var liveStatus = ""
        val isLive: Boolean
        if (gatherLiveStatus == 1) {
            liveStatus = context.getString(R.string.Pigeon_collection_living)//"集鸽直播中"
            isLive = false
        } else if (carLiveStatus == 1) {
            liveStatus = context.getString(R.string.Live_stream_of_vehiclering)//"车辆直播中"
            isLive = false
        } else if (backLiveStatus == 1) {
            liveStatus = context.getString(R.string.Homing_living)//"归巢直播中"
            isLive = false
        } else {
            isLive = true
            when (passStatus) {
                1 -> liveStatus = context.getString(R.string.item_train_fly_main_list_not_start)//"未开始"
                4 -> liveStatus = context.getString(R.string.Pigeons_gathering)//"集鸽中"
                5 -> liveStatus = context.getString(R.string.End_of_collection)//"集鸽结束"
                6 -> liveStatus = context.getString(R.string.in_the_game)//"比赛中"
                7 -> liveStatus = context.getString(R.string.end_of_game)//"比赛结束"
                else -> holder.setGone(R.id.llItemRaceLiveStatus, true)
            }
        }
        holder.setText(R.id.tvItemRaceLiveStatus, liveStatus)
        holder.setGone(R.id.ivLiving, isLive)

        val isPlayBack = !(gatherLiveStatus == 2 || carLiveStatus == 2 || backLiveStatus == 2)
        holder.setGone(R.id.tvVideoPlayBack, isPlayBack)
    }
}